package me.ylduan.ch2.controller;

import me.ylduan.ch2.model.Customer;
import me.ylduan.ch2.service.CustomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 客户列表
 *
 * @author Zero
 * @created 2017/5/9 14:45
 */
@WebServlet("/customer")
public class CustomerServlet extends HttpServlet {
    private CustomerService service;

    public void init() throws ServletException {
        service = new CustomerService();
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Customer> customerList = service.getCustomerList();
        req.setAttribute("customerList", customerList);

        // req.getRequestDispatcher("/WEB-INF/view/customer.jsp").forward(req, resp); 也可以
        req.getRequestDispatcher("WEB-INF/view/customer.jsp").forward(req, resp);
    }
}
